<?php
/**
 * 搜索
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: SearchController.class.php v1.0 2014-06-23 17:27:03 $
 */
namespace Home\Controller;
class SearchController extends CommonController{
    public function _initialize() {
        parent::_initialize();
    }
    
    public function index() {
        $typeid = I("typeid", 0, "intval");
        $model_id = I("mid", 0, "intval");
        $keyword = I("keyword", NULL, "trim");
        if(empty($keyword)){
            $keyword = I("q", "", "trim");
        }
        
        $oldkeyword = $keyword = FilterSearch(stripslashes($keyword));
        $keyword = addslashes(cn_substr($keyword,30));
        
        if($keyword==''){
            $this->error('关键字不能为空！');
            exit();
        }
        
        //检查搜索间隔时间
        $lockfile = YDCMS_DATA .'time.lock.inc';
        $lasttime = file_get_contents($lockfile);
        $cfg_search_time = C("SEARCH_TIME");
        if(!empty($lasttime) && ($lasttime + $cfg_search_time) > time())
        {
            $this->error('管理员设定搜索时间间隔为'.$cfg_search_time.'秒，请稍后再试！');
            exit();
        }
        
        $where['_string'] = D("Search")->GetKeywordSql($keyword);
        $order = "click DESC, id DESC, pubdate DESC";
        $result = $this->getPagination("Content", $where, "*", $order);
        //var_dump($where, $result);die;
        $this->assign("list", $result['data']);
        $this->assign("page", $result['page']);
        $this->assign("count", $result['total_rows']);
        $this->assign("search_keyword", $oldkeyword);
        $this->display();
        PutFile($lockfile, time());
    }
}
